(function(){
    document.domain='bibi321.com';
    var parentRegCode = getURLParameterString("parentRegCode");//location.search.substr(1), // 获取url中"?"符后的字串
    if(parentRegCode != null){
        window.parentRegCode=parentRegCode;
        localStorage.setItem("parentRegCode",parentRegCode);
        document.cookie="parentRegCode=" + parentRegCode + ";domain=bibi321.com;path=/";
        console.log("parentRegCode:"+ getCookie("parentRegCode"));
    }
})();
/**
 * regcode 注册码
 */
function card_package_create(userId){
     var regCode=window.parentRegCode;
     var url="http://47.106.86.78:6062/api/user/userReg";
     if(regCode){
         $.post(url,{'regCode':regCode,'userId':userId},function(result){
             console.log(result)
         });
     }
}

function getURLParameterString(name)
{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null) {
        return  unescape(r[2]);
    }
    return null;
}

function getCookie(cookieName) {
    return getCookieByCodeType(cookieName, "");
}

function getURLEncodeCookie(cookieName) {
    return getCookieByCodeType(cookieName, "URLENCODE");
}

function getBase64Cookie(cookieName) {
    return getCookieByCodeType(cookieName, "BASE64");
}

function getCookieByCodeType(cookieName, codeType) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for (var i = 0; i < arrCookie.length; i++) {
        var arr = arrCookie[i].split("=");
        if(cookieName == arr[0]) {
            if(codeType == "BASE64") {
                return $.base64().decode(arr[1]);
            }else if(codeType == "URLENCODE"){
                return  decodeURIComponent(arr[1]);
            }else {
                return arr[1];
            }
        }
    }
    return "";
}